<?php

namespace app\admin\service;

use app\admin\model\Finance;
use think\facade\Db;

class FinanceService extends BaseService
{
    public function __construct()
    {
        $this->model = new Finance();
    }

    public function getList()
    {
        $data = request()->param();


        $where = [];
        if (isset($data['add_time'])) {
            if ($data['add_time'] != "") {
                $where[] = ['o.create_time', '>=', strtotime($data['add_time'])];
            }
        }
        if (isset($data['end_time'])) {
            if ($data['end_time'] != "") {
                $where[] = ['o.create_time', '<=', strtotime($data['end_time']) + 86400];
            }
        }
        if (isset($data['store_id'])) {
            if ($data['store_id'] != "") {
                $where[] = ['m.id', '=', ($data['store_id'])];
            }
        }
        $list = Db::name('admin_price')
            ->alias('o')
            ->join('mini_room_list m', 'm.id=o.store_id')->field('o.*,m.room_name')

            ->where($where)->order('o.create_time desc')->page(PAGE, PERPAGE)
            ->select();





        $count = Db::name('admin_price')
            ->alias('o')
            ->join('mini_room_list m', 'm.id=o.store_id')
            ->where($where)->order('o.create_time desc')->page(PAGE, PERPAGE)
            ->count();


        //返回结果
        $message = array(
            "msg" => '操作成功',
            "code" => 0,
            "data" => $list,
            "count" => $count,
        );
        return $message;
    }
}